package map.abstractor.xaml2uimodel.base;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Element;
import org.xml.sax.SAXException;


public class XamlDocument extends XMLDocument {

	/**
	 * Constructor
	 * 
	 * @param filename
	 * @throws IOException 
	 * @throws SAXException 
	 * @throws ParserConfigurationException 
	 */
	public XamlDocument(String filename) throws ParserConfigurationException, SAXException, IOException {
		super(filename);
		application = (XMLElement) process(document.getDocumentElement());
	}

	public XamlDocument(InputStream in) throws ParserConfigurationException, SAXException, IOException {
		super(in);
		application = (XMLElement) process(document.getDocumentElement());
	}

	
	protected XMLObject process(Element element) {
		XMLObject n=new XamlElement(element);
		XMLObject child;
		if (n != null && n instanceof XamlElement)
			for (int i = 0; i < element.getChildNodes().getLength(); i++)
				if (element.getChildNodes().item(i).getNodeType() == Element.ELEMENT_NODE) {
					child = (XMLObject) process((Element) (element
							.getChildNodes().item(i)));
					if (child != null) {
						if (child instanceof XamlElement)
							((XamlElement) n).addChild((XamlElement) child);
						else if (child instanceof XamlProperty)
							((XamlElement) n).addProperty((XamlProperty) child);
					}

				}
		return n;
	}

}
